package com.example.java8.timeapi;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.*;

/**
 * TODO
 *
 * @author qibao
 * @version v0.1 2020/12/17
 */
public class SimpleDateFormatter {
    private static ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(10, 10, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue<>());


    public static void main(String[] args) throws Exception {

        nowDateFormater();

        poolExecutor.shutdown();
    }

    public static void nowDateFormater() throws ExecutionException, InterruptedException {

        List<String> list = new ArrayList<>();

        Callable<String> callable = new Callable() {
            @Override
            public String call() throws Exception {
                return LocalDate.parse("2020/10/10", DateTimeFormatter.ofPattern("yyyy/MM/dd")).toString();
            }
        };

        for (int i = 0; i < 30; i++) {
            list.add(poolExecutor.submit(callable).get());
        }

        list.stream()
                .forEach(System.out::println);

    }

    public static void oldDateFormater() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        List<Future<Date>> list = new ArrayList<>();

        Callable<Date> callable = new Callable() {
            @Override
            public Object call() throws Exception {
                return simpleDateFormat.parse("20201010");
            }
        };

        for (int i = 0; i < 30; i++) {
            list.add(poolExecutor.submit(callable));
        }

        list.stream()
                .forEach(System.out::println);

    }
}
